#include "iostream"
#include "map"
#include "vector"
#include <stack>
#include <unordered_map>
#define GF_DEBUG
class Solution {
public:
  bool isValid(std::string s) {
    std::unordered_map<char, char> map;
    std::stack<char> stack;
    map['}'] = '{';
    map[')'] = '(';
    map[']'] = '[';
    for (int i = 0; i < s.size(); i++) {
      char c = s[i];
      if (map.find(s[i]) == map.end() && !stack.empty() &&
          map[c] == stack.top()) {
        stack.push(c);
      } else {
        stack.pop();
      }
    }
    return stack.empty();
  }
};
int main() {
  Solution s;
  std::cout << s.isValid("([])");
}